/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package client.domainModels.NodeImpl;

import java.util.ArrayList;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import app.model_package.CaseModel;

import GUI.view.MultiLineTable;

import client.domainModels.Node.Node;

/**
 * 
 * @author Wei WANG
 */
public class Case extends AbstractNode {

	private static ArrayList<String> history = new ArrayList<String>();
	
	@Override
	public String[] getChildNodeNames() {
		String[] strings = { "Event" };
		return strings;
	}

	@Override
	public String[] getNodeAttributes() {
		// TODO Auto-generated method stub
		String[] attributes = { "name" };
		return attributes;
	}

	public String toString() {
		return "Case: " + getID();
	}
	
	public CaseModel getCaseModel(){
		CaseModel ret = new CaseModel(this.getID());
		
		ArrayList<AbstractNode> aux = this.getChildNodes("Event");
		for (int i=0;i<aux.size();i++){
			if (aux.get(i)!=null)
				ret.addEvent(((Event) aux.get(i)).toEventModel());
		}
		System.out.println("Taille de cas: "+ret.getEventsList().size());
		return ret;
	}
	
	@Override
	public String getStringRepresentation() {
		// TODO Auto-generated method stub
		String ret ="  <case name='" +this.getID()+"'>\n";
		ret+=this.childReader("Event");
		ret+="  </case>\n";
		return ret;
	}
	private String childReader(String type){
		String ret="";
		ArrayList<AbstractNode> aux = this.getChildNodes(type);
		if (aux != null){
			for(int i = 0;i<aux.size();i++){
				ret+=aux.get(i).getStringRepresentation();
			}
		}
		return ret;
	}
	
	 public boolean verifyComplete(){
	    	boolean b = true;
	    	int size = getChildNames_childObjs().get("Event").size();
	    	if(size>0){
	    		for(int i=0;i<size;i++){
	    			Event events = (Event) getChildNames_childObjs().get("Event").get(i);
	    			if(!events.verifyComplete()){
	    				b=false;
	    				break;
	    			}
	    		}
	    	}else{
	    		b=false;
	    	}
			return b;
		}
	 public void addRecordInHistory(String s){
			if(history.indexOf(s)==-1){
				history.add(s);
			}
		}
		
		public ArrayList<String> getHistoryList(){
			return history;
		}
		
		public String[] getHistorySet(){
			return (String[]) history.toArray();
		}

		@Override
		public String getRep() {
			// TODO Auto-generated method stub
			return this.getID();
		}
}
